{{{
{{use "jquery", ui=True}}
{{use "jqutils",ajaxForm=True}}
{{use "poshytip"}}
{{use "jqeasyui"}}
<script>

var create_result_process = function(target, opt){
    return function(r){
        var t = $(target);
        t.find('input,textarea,select').poshytip('hide');
        show_simple_message(r.message);
        if (r.success){
            opt.success(r.data);
        } else if (!r.success){
            $.each(r.data, function(key, value){
                var el = t.find('input[name='+key+'],select[name='+key+'],textarea[name='+key+']');
                $(el).poshytip({
                    className:'tip-yellowsimple',
                    content: value,
                    showOn: 'none',
                    alignTo: 'target',
                    alignX: 'inner-left',
                    offsetX: 0,
                    offsetY: 5,
                    closeButton: true
                });
                $(el).poshytip('show');
                $(el).focus(function(){
                    $(this).poshytip('hide');
                });
            });
        }
    }
}

function success(data){
    window.location.href = '/tasks/develop/' + data.id;
}

$(function(){
    $('select[name=requirement]').change(function(){
        var el = $(this);
        get_select('version_headerId', "/tasks/get_tasks", {value:el.val()});
        get_select('task_type', "/tasks/get_tasktypes", {value:el.val()});
    });
    $('select[name=task_sys]').change(function(){
        var el = $(this);
        get_select('requirement', "/tasks/get_reqs", {value:el.val()});
        get_select('assignment', "/tasks/get_asss", {value:el.val()});
    });
    
    //设置poshytip关闭图片
    $.fn.poshytip.defaults.closeImage = '{{=url_for_static("jqutils/cross_grey_small.png")}}';
    
    //生成ajaxForm的处理函数
    var result_process = create_result_process('form.yform', 
        {success:success});

    var options = { 
        success: result_process,  // post-submit callback 
        dataType: 'json'
    }; 
    // bind form using 'ajaxForm' 
    $('form.yform').ajaxForm(options); 
});
</script>
}}}
form.yform#addTask
    .group
        p.description | 任务信息
        field name=task_sys
        field name=requirement
        field name=assignment
        field name=version_headerId
        field name=task_type
        field name=name
        field name=sub_sys
        field name=sub_sys_name
        field name=stakeholder
        field name=desc
    
    .group
        .line
            p.description | 预计工作量（单位：人天）
            field name=amount_inner
            field name=amount_outer
    
    .group
        .line
            p.description | 任务周期
            field name=begin_time
            field name=end_time
    
    .group 
        field name=memo
    
    buttons
        button | 保存
